package com.kukudexin.time.stream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
 * @author: 酷酷的鑫
 * @Date: 2021/8/10 15:00
 * @description:
 */
public class Test03 {
    public static void main(String[] args) {
        List<Car> carshop = addDate();
//        carshop.stream().sorted((c1,c2) -> c2.getPrice()-c1.getPrice()).map(Car::getBrand).distinct().forEach(System.out::println);
//        carshop.stream().filter(Car::isSold).sorted(Comparator.comparing(Car::getPrice)).map(Car::getBrand).forEach(System.out::println);
//        carshop.stream().map(Car::getType).distinct().forEach(System.out::println);
//        carshop.stream().filter(s -> s.getType() == CarType.SUV).map(Car::getBrand).forEach(System.out::println);
//        carshop.stream().filter(s->s.getPrice()<40).map(Car::getBrand).distinct().forEach(System.out::println);

//        System.out.println(carshop.stream().filter(s -> !s.isSold()).count());

//        System.out.println(carshop.stream().map(Car::getPrice).reduce(Integer::max).get());
        System.out.println(carshop.stream().filter(Car::isSold).collect(Collectors.maxBy(Comparator.comparing(Car::getPrice))).get().getBrand());
    }

    private static List<Car> addDate(){
        List<Car> carshop = new ArrayList<>();
        carshop.add(new Car("Benz", false, 68, CarType.SUV));
        carshop.add(new Car("Audi", true, 28, CarType.HATCHBACK));
        carshop.add(new Car("BMW", false, 88, CarType.HATCHBACK));
        carshop.add(new Car("Geeley", true, 18, CarType.HATCHBACK));
        carshop.add(new Car("Xiali", true, 8, CarType.THREECOMPARTMENT));
        carshop.add(new Car("Haval", false, 18, CarType.SUV));
        carshop.add(new Car("Jeep", true, 38, CarType.SUV));
        carshop.add(new Car("Honda", false, 28, CarType.THREECOMPARTMENT));
        carshop.add(new Car("Chery", true, 18, CarType.THREECOMPARTMENT));
        carshop.add(new Car("Benz", false, 58, CarType.THREECOMPARTMENT));
        return carshop;
    }
}
